const cookie = {}

cookie.setCookie = function (name, value, expiredays) {
  let exdate = new Date(), _cookie;
  exdate.setDate(exdate.getDate() + expiredays);
  _cookie = name + "=" + escape(value) + ";path=/;";

  if (expiredays) {
    _cookie += "expires = " + exdate.toGMTString() + ";"
  }

  document.cookie = _cookie
}

cookie.getCookie = function (name) {
  var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");

  if (arr = document.cookie.match(reg)) return unescape(arr[2]);
  else return null;
}

cookie.clearCookie = function (name) {
  cookie.setCookie(name, "", -1);
}


export default {
  name: "cookie",
  default: cookie
}